define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'finance/want_to_buy/index',
                    // add_url: 'finance/want_to_buy/add',
                    // edit_url: 'finance/want_to_buy/edit',
                    // del_url: 'finance/want_to_buy/del',
                    // multi_url: 'finance/want_to_buy/multi',
                    table: 'want_to_buy',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName:'id',
                sortOrder:'desc',
                commonSearch: true,
                strictSearch: true,
                search:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), sortable: true},
                        {field: 'name', title: __('Name'), operate:'like'},
                        {field: 'title', title: __('Title'), operate:'like'},
                        {field: 'province_name', title: __('Provincename'), operate:'like'},
                        {field: 'city_name', title: __('Cityname'), operate:'like'},
                        {field: 'region_name', title: __('Regionname'), operate:'like'},
                        {field: 'contacts', title: __('Contacts'), operate:'like'},
                        {field: 'contacts_tel', title: __('Contactstel'), operate:'like'},
                        {field: 'is_extension', title: __('Isextension'), formatter: Table.api.formatter.status, searchList: {0: __('否'), 1: __('是')}},
                        {field: 'is_top', title: __('Istop'), formatter: Table.api.formatter.status, searchList: {0: __('否'), 1: __('是')}},
                        {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {normal: __('Normal'), hidden: __('Hidden')}},
                        {field: 'to_examine', title: __('是否审核'), formatter: Table.api.formatter.status, searchList: {1: __('是'), 2: __('否')}},
                        {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'updatetime', title: __('Updatetime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'ajax',
                                    text: __('审核'),
                                    title: __('审核'),
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    url: 'finance/want_to_buy/to_examine',
                                    confirm: '确认通过审核吗?',
                                    visible: function (row) {
                                        if (row.to_examine == 2) {
                                            return true;
                                        }
                                        return false;
                                    },
                                    success: function () {
                                        $(".btn-refresh").trigger("click");//提交后刷新当前页面，你会需要这个的！
                                    }
                                },
                            ]
                        }
                    ]
                ]
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});